/*
	ASSUME THAT 
		Y_MAX - Max y-coordinate value
*/
#include "paddle.h"
#include "CSurface.h"

Paddle::Paddle(SDLKey upKey, SDLKey downKey, point StartPosition)
{
	Up = upKey;
	Down = downKey;
	location = StartPosition;

	filename = "paddle.bmp";
	surf = CSurface::OnLoad(filename);
	width = 10;
	height = 50;
}

void Paddle::input(SDL_Event* e)
{
	// create an array of the keyboard
	Uint8 *keystate = SDL_GetKeyState(NULL);

	// filter the input
	switch(e->type)
	{
		case SDL_KEYDOWN:		
			// assign two keys that will be used 
			// to move the paddle up/down
			if (keystate[Up])
				location.y -= 10;		// move by 10 pixels
			else if (keystate[Down])
				location.y += 10;
	}

	// basic collision detection with borders
	if (location.y > (Y_MAX - height))
		location.y = Y_MAX - height;
	else if (location.y < 0)
		location.y = 0;
}

void Paddle::draw(SDL_Surface* display)
{
	// Draw the paddle!
	CSurface::OnDraw(display, surf, location.x, location.y, 0, 0, width, height);
}

